package com.yangyang.androidconnect;

import android.app.Application;
import android.content.Context;

import com.yangyang.androidconnect.phoneinfo.DataCollectionService;
import com.yangyang.androidconnect.phoneinfo.DatabaseHelper;
import com.yangyang.androidconnect.phoneinfo.service.CallLogService;
import com.yangyang.androidconnect.phoneinfo.service.ContactService;
import com.yangyang.androidconnect.phoneinfo.service.SMSService;
import com.yangyang.androidconnect.service.FileIndexService;

import lombok.Data;

// MyApplication.java
@Data
public class MyApplication extends Application {
    private static MyApplication instance;

    private DatabaseHelper databaseHelper;
    private DataCollectionService dataCollectionService;
    private ContactService contactService;
    private CallLogService callLogService;
    private SMSService smsService;

    private FileIndexService fileIndexService;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initializeServices();
    }

    private void initializeServices() {
        // 使用应用上下文，避免内存泄漏
        databaseHelper = new DatabaseHelper(getApplicationContext());
        dataCollectionService = new DataCollectionService(getApplicationContext());

        // 这些服务可以通过 DataCollectionService 获取，或者单独初始化
//        contactService = new ContactService(getApplicationContext());
//        callLogService = new CallLogService(getApplicationContext());
//        smsService = new SMSService(getApplicationContext());

        // Application Context - 应用级别的上下文
        Context appContext = getApplicationContext();

        fileIndexService = new FileIndexService(appContext);
    }

    public static MyApplication getInstance() {
        return instance;
    }

}